package com.bj.dz.service.impl;

import com.bj.dz.entity.TaskRecord;
import com.bj.dz.mapper.TaskRecordMapper;
import com.bj.dz.service.TaskRecordService;
import com.bj.dz.util.Constants;
import com.bj.dz.util.EmptyUtils;
import com.bj.dz.util.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class TaskRecordServiceImpl implements TaskRecordService {

    @Resource
    private TaskRecordMapper taskRecordMapper;

    public TaskRecord getTaskRecordById(Integer id){
        return taskRecordMapper.getTaskRecordById(id);
    }

    public List<TaskRecord>	getTaskRecordListByMap(Map<String,Object> param){
        return taskRecordMapper.getTaskRecordListByMap(param);
    }

    public Integer getTaskRecordCountByMap(Map<String,Object> param){
        return taskRecordMapper.getTaskRecordCountByMap(param);
    }

    @Transactional
    public boolean addTaskRecord(TaskRecord taskRecord){
            return taskRecordMapper.insertTaskRecord(taskRecord)>0?true:false;
    }

    @Transactional
    public boolean modifyTaskRecord(TaskRecord taskRecord){
        return taskRecordMapper.updateTaskRecord(taskRecord)>0?true:false;
    }

    @Transactional
    public boolean deleteTaskRecordById(Integer id){
        return taskRecordMapper.deleteTaskRecordById(id)>0?true:false;
    }

    public Page<TaskRecord> queryTaskRecordPageByMap(Map<String,Object> param, Integer pageNo, Integer pageSize){
        Integer total = taskRecordMapper.getTaskRecordCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<TaskRecord> taskRecordList = taskRecordMapper.getTaskRecordListByMap(param);
        page.setRows(taskRecordList);
        return page;
    }

}
